package com.jiexin.controller;

import com.jiexin.common.JsonData;
import com.jiexin.dto.DeptLevelDto;
import com.jiexin.param.AclModuleParam;
import com.jiexin.param.DeptParam;
import com.jiexin.service.SysAclModuleService;
import com.jiexin.service.SysTreeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

/**
 * @Author: Jay_Liu
 * @Description: 权限
 * @Date: Created in 13:22 2018/4/8 0008
 * @Modified By:
 */
@Controller
@RequestMapping("/sys/aclModule")
@Slf4j
public class SysAclModuleController {

    @Resource
    private SysAclModuleService sysAclModuleService;

    @Resource
    private SysTreeService sysTreeService;

    @RequestMapping("/acl.page")
    public ModelAndView page(){
        return new ModelAndView("acl");
    }

    @RequestMapping("/save.json")
    @ResponseBody
    //保存
    public JsonData saveAclModule(AclModuleParam aclModuleParam) {
        sysAclModuleService.save(aclModuleParam);
        return JsonData.success();
    }

    @RequestMapping("/update.json")
    @ResponseBody
    //更新
    public JsonData updateAclModule(AclModuleParam aclModuleParam) {
        sysAclModuleService.update(aclModuleParam);
        return JsonData.success();
    }

    @RequestMapping("/tree.json")
    @ResponseBody
    //权限树
    public JsonData tree() {
        return JsonData.success(sysTreeService.aclModuleTree());
    }

    public static void main(String[] args) throws ParseException {

        SimpleDateFormat sdf1 = new SimpleDateFormat("MMM d, yyyy K:m:s a", Locale.ENGLISH);
        Date d2 = null;
        try {
           d2 = sdf1.parse("Apr 16, 2018 2:56:57 PM");
        } catch (ParseException e){
        }
        String date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(d2);
        System.out.println(date);
    }

    @RequestMapping("/delete.json")
    @ResponseBody
    //删除
    public JsonData deleteAclModule(@RequestParam("aclModuleId") int aclModuleId) {
        sysAclModuleService.delete(aclModuleId);
        return JsonData.success();
    }
}
